package lookMessage;

import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Bean.SqlBean;
import loginRegister.LoginBean;

/**
 *
 * @author 刘杉
 */
public class LookMessageServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws  IOException {
        String userName="";
        HttpSession session=request.getSession();
        LoginBean nn=(LoginBean)session.getAttribute("login");
        if(nn==null){
            response.sendRedirect("http://localhost:8080/login.jsp");
        }else{
            userName=nn.getUserName();
            try{
                SqlBean sb=new SqlBean();
                sb.connectSQL();
                ResultSet rs=null;
                String sql="select * from user where userName='"+userName+"'";
                rs=sb.executeQuery(sql);
                LookMessageBean mm=new LookMessageBean();
                while(rs.next()){
                    mm.setName(rs.getString("name"));
                    mm.setSex(rs.getString("sex"));
                    mm.setIdCard(rs.getString("idCard"));
                    mm.setBirth(rs.getString("birth"));
                    mm.setNation(rs.getString("nation"));
                    mm.setEdu(rs.getString("edu"));
                    mm.setWork(rs.getString("work"));
                    mm.setMonthPay(rs.getString("monthPay"));
                    mm.setPhone(rs.getString("phone"));
                    mm.setPlace(rs.getString("place"));
                    mm.setEmail(rs.getString("email"));
                    mm.setLevel(rs.getString("level"));
                    mm.setPicture(rs.getString("picture"));
                    mm.setDgut_username(rs.getString("dgut_username"));
                }
                HttpSession session1=request.getSession();
                session1.setAttribute("wordlist", mm);
                sb.closeSQL();
                response.sendRedirect("http://localhost:8080/lookMessage/lookMessage.jsp");
            }catch(Exception e){
                e.printStackTrace();
            }
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws  IOException {
        doGet(request, response);
    }

}
